package cn.xiaomubiao.oschine.fragment.myinfofragment.message;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.activity.MyInfoBaseActivity;
import cn.xiaomubiao.oschine.adapter.myinfo_message.AtMeAdapter;
import cn.xiaomubiao.oschine.adapter.tweets_pager_adapter.TweetsBaseRecyclerAdapter;
import cn.xiaomubiao.oschine.base.BaseEachFragment;
import cn.xiaomubiao.oschine.base.BaseRecyclerViewAdapter;
import cn.xiaomubiao.oschine.bean.Active;
import cn.xiaomubiao.oschine.bean.ActiveList;
import cn.xiaomubiao.oschine.bean.Tweet;
import cn.xiaomubiao.oschine.bean.TweetsList;
import cn.xiaomubiao.oschine.contants.Host;
import cn.xiaomubiao.oschine.util.HttpUtil;
import cn.xiaomubiao.oschine.viewpagerfragment.tweetspagerfragment.TweetsDetailFragment;

/**
 * @author
 * @version 1.0
 * @date 2017/4/5
 */

public class MyInfoMessageAndMeFragment extends BaseEachFragment {
    @BindView(R.id.recyler_pager)
    XRecyclerView mRecylerPager;
    /*@BindView(R.id.refresh_pager)
    SwipeRefreshLayout mRefresh;*/
    private View mView;
    private List<Active> mActives;

    @Override
    public View loadSuccess() {
        mView = View.inflate(getActivity(), R.layout.view_tweets_pager_layout, null);
        ButterKnife.bind(this, mView);
        initRecylerView();
        return mView;
    }

    private void initRecylerView() {
        AtMeAdapter atMeAdapter = new AtMeAdapter(mActives);
        mRecylerPager.setAdapter(atMeAdapter);
        mRecylerPager.setLayoutManager(new LinearLayoutManager(getContext()));
        atMeAdapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnRecycleViewItemClickListener() {
            @Override
            public void onClick( View view, int position ) {
                position -= 1;
                Intent intent = new Intent(getActivity(), MyInfoBaseActivity.class);
                intent.putExtra("id",mActives.get(position).getId());
                intent.putExtra("title","动弹详情");
                intent.putExtra("className", TweetsDetailFragment.class.getName());
                startActivity(intent);
            }
        });

    }

    @Override
    public void loadData() {
        HttpUtil<ActiveList> httpUtil = new HttpUtil<>(getContext(), ActiveList.class);
        String url = Host.HOST_DEFAULT+"list/active_list2/page0.xml";
        httpUtil.getStringData(url, new HttpUtil.OnGetDataListener<ActiveList>() {



            @Override
            public void onSuccess( ActiveList activeList ) {
                mActives = activeList.getActivelist();
                mCommonPager.showSuccessPager(mActives);
            }

            @Override
            public void onFailure( Exception e ) {
                mCommonPager.showFailPager();
            }
        });
    }
}
